<?php
/**
 * Created by PhpStorm.
 * User: cy
 * Date: 2017/5/30
 * Time: 12:58
 */

header("Access-Control-Allow-Origin:*");//允许跨域

//配置数据库配置创建连接
$conn=new mysqli("127.0.0.1","root","","tiangou");

//配置连接的字符集
mysqli_query($conn, "set names utf8");

//写sql语句。执行
$sql="SELECT*FROM products WHERE prostatus='1'";

//返回结果
$result=$conn->query($sql);
//print_r($result);// 返回结果中num-rows为8,表示已经添加的8条数据

$arrlist=array();
if($result->num_rows>0){
//遍历$result
    while($row=$result->fetch_assoc()){
        array_push($arrlist,$row);
    }
}
print_r(json_encode($arrlist));